SetConfiguredAxesCount

配置模擬軸的數量。模擬軸的數量取決於有多少給定值超過實際的硬體數量,若給定值大於實際軸的數量,KINGSTAR 會顯示所有實際軸與模擬軸。例如,有五個實際軸而給定值為七,則會顯示五個實際軸及兩個模擬軸;若給定值小於或等於實際軸的數量,KINGSTAR 會顯示所有實際軸的數量,而無模擬軸。

語法

KsError SetConfiguredAxesCount(
     int Count
);

參數

Count:模擬軸的數量,最大值為 256。

回傳值

如果此函式執行成功,會回傳 errNoError,否則會傳回錯誤碼。如需更多有關錯誤碼的資訊,請參閱 KsError 清單。

備註

允許工程師在未取得所有硬體狀態下測試應用程式。模擬軸需在用 ConfigureAxis 配置前使用 SetConfiguredAxesCount 創建,此函式必須在 Create 後及 Start 前呼叫,一旦連結建立,模擬軸即無法修改。

可用的 EtherCAT 狀態

ecatOffline

範例

複製
/////////////////////////////////////////////////////////////////////////
//
// This code snippet demonstrates how to configure simulated hardware
// in KINGSTAR subsystem. Please be aware that if any actual hardware
// detected in the bus scan procedure the configuration will be replaced
// by automated configuration.
//
/////////////////////////////////////////////////////////////////////////

#define AXIS_COUNT  2
#define IO_COUNT    3

// Variable declaration
KsError nRet = errNoError;
KsCommandStatus Command = { 0 };
SubsystemStatus Subsystem = { ecatOffline, ecatOffline, 0, 0, 0, {ecatOffline}, {ecatOffline}, {axisOffline} };
int axesCount = 0, ioCount = 0;

// Link to the KINGSTAR subsystem
nRet = Create(0, 0);

nRet = SetConfiguredAxesCount(AXIS_COUNT);
nRet = SetConfiguredIoCount(IO_COUNT);

for (int i = 0; i < AXIS_COUNT; i++)
{
    SlaveStatus axisDefinition = { "Simulated Axis", 0 };
    
    // Assign resolution for the simulated axes
    nRet = ConfigureAxis(0, axisDefinition, 131072);
}

for (int i = 0; i < IO_COUNT; i++)
{
    SlaveStatus simulatedIo = { "Simulated IO", 0 };
    
    // Assign input length for the simulated IOs
    simulatedIo.InputLength = 32;
    nRet = ConfigureIo(i, simulatedIo);
}

// By setting the timeout to a short interval and abort Start() on timeout,
// KINGSTAR subsystem will stop scanning for real hardware and start with
// the simulated hardware instead.
Command = WaitForCommand(2, TRUE, Start());

// Get the configured hardware count. It can be used by another KINGSTAR application process.
nRet = GetConfiguredAxesCount(&axesCount);
nRet = GetConfiguredIoCount(&ioCount);

使用需求

  RT Win32
最低支援版本 4.0 4.0
標頭檔 ksapi.h ksapi.h
程式庫 KsApi_Rtss.lib KsApi.lib

參見

ConfigureAxis

GetConfiguredAxesCount